package mybatis1.com.config.dao.teat;

import mybatis1.com.config.dao.MybitsUtil;
import mybatis1.com.config.dao.StuDaol;
import mybatis1.com.config.model.ExamResult;
import mybatis1.com.config.model.Grade;
import mybatis1.com.config.model.Student;
import org.apache.ibatis.session.SqlSession;

import java.sql.Date;
import java.util.List;

public class TestStu {
    public static void main(String[] args) {
        TestStu testStu = new TestStu();
        //testStu.find();
      //testStu.search();
        //testStu.search1();
        //testStu.search2();
       // testStu.search3();
        //testStu.update();
       // testStu.select();
        testStu.select1();
    }
    public void find(){
        SqlSession sqlSession = MybitsUtil.getSqlSession();
        StuDaol mapper = sqlSession.getMapper(StuDaol.class);
        List<Student> stu = mapper.find();
        for (Student stu1 : stu) {
            System.out.println(stu1);
        }
        MybitsUtil.close(sqlSession);
    }
    public void search(){
        SqlSession sqlSession = MybitsUtil.getSqlSession();
        Examdao mapper = sqlSession.getMapper(Examdao.class);
        ExamResult search = mapper.search(1);
        System.out.println(search);
        MybitsUtil.close(sqlSession);
    }public void search1(){
        SqlSession sqlSession = MybitsUtil.getSqlSession();
        Examdao mapper = sqlSession.getMapper(Examdao.class);
        List<ExamResult> exam = mapper.search1(97);
        for (ExamResult examResult : exam) {
            System.out.println(examResult);
        }
        MybitsUtil.close(sqlSession);
    }
    public void search2(){
        SqlSession sqlSession = MybitsUtil.getSqlSession();
        StuDaol mapper = sqlSession.getMapper(StuDaol.class);
        List<Student> search = mapper.search(11);
        for (Student student : search) {
            System.out.println(student);
        }
        MybitsUtil.close(sqlSession);
    }
    public void search3(){
        SqlSession sqlSession = MybitsUtil.getSqlSession();
        StuDaol mapper = sqlSession.getMapper(StuDaol.class);
        List<Student> stu = mapper.search1(2,2,"李", "1", Date.valueOf("2017-01-01"), Date.valueOf("2020-09-15"));
        for (Student student : stu) {
            System.out.println(student);
        }
    }
    public void update(){
        SqlSession sqlSession = MybitsUtil.getSqlSession();
        StuDaol mapper = sqlSession.getMapper(StuDaol.class);
        int i = mapper.update("猪八戒", 216);
        System.out.println(i);
        MybitsUtil.commit(sqlSession);
        MybitsUtil.close(sqlSession);

    }
    public void select(){
        SqlSession sqlSession = MybitsUtil.getSqlSession();
        GraDao mapper = sqlSession.getMapper(GraDao.class);
        List<Grade> gra = mapper.search(2);
        for (Grade grade : gra) {
            System.out.println(grade);
            List<Student> stu = grade.getStu();
            System.out.println(stu.size());
        }

        MybitsUtil.close(sqlSession);
    }
    public void select1(){
        SqlSession sqlSession = MybitsUtil.getSqlSession();
        GraDao mapper = sqlSession.getMapper(GraDao.class);
        List<Grade> gra = mapper.search1("高");
        for (Grade grade : gra) {
            System.out.println(grade);
        }
        MybitsUtil.close(sqlSession);
    }
}
